package com.learnosity.extendotext.style
{
	import com.learnosity.extendotext.Rule;
	import flash.text.engine.ElementFormat;
		
	public class Color
	{
		protected static const black:uint = 0x000000;
		protected static const silver:uint = 0xC0C0C0;
		protected static const gray:uint = 0x808080;
		protected static const white:uint = 0xffffff;
		protected static const maroon:uint = 0x800000;
		protected static const red:uint = 0xff0000;
		protected static const purple:uint = 0x800080;
		protected static const fuchsia:uint = 0xFF00FF;
		protected static const green:uint = 0x008000;
		protected static const lime:uint = 0x00FF00;
		protected static const olive:uint = 0x808000;
		protected static const yellow:uint = 0xFFFF00;
		protected static const navy:uint = 0x000080;
		protected static const blue:uint = 0x0000FF;
		protected static const teal:uint = 0x008080;
		protected static const aqua:uint = 0x00FFFF;

		static public function apply(rule:Rule,format:ElementFormat):ElementFormat{
			//Set value to lower case
			rule.value = rule.value.toLowerCase();

			//Is this a hex has value?
			if(rule.value.indexOf('#') != -1){
				//Strip the # and parse a hex
				format.color = parseInt(rule.value.replace('#',''),16);
			}
			//Else check if a named value
			else if(Color[rule.value])
			{
				format.color = Color[rule.value];
			}
		
			return format;
		}

	}
}